<?php
/**
 *CouponController
 * @author tan bing
 * @date 2021-09-15 17:19
 */


namespace Modules\Coupon\Http\Controllers\Admin;


use Modules\Coupon\Services\Admin\CouponServices;

class CouponController extends AdminBaseController
{

    /**
     * @var CouponServices
     * @author tan bing
     */
    private $couponServices;

    /**
     * CouponController constructor.
     * @param CouponServices $couponServices
     * @author tan bing
     * @date 2021-09-15 17:25
     */
    public function __construct(CouponServices $couponServices)
    {
        parent::__construct();
        $this->couponServices = $couponServices;
    }

    /**
     * 优惠券管理页面
     * @return bool|\Illuminate\Auth\Access\Response|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-09-15 17:30
     */
    public function index()
    {
        $param = $this->couponServices->getRequestParam();
        return view('coupon::admin.coupon.index', compact('param'));
    }

    /**
     * 优惠券编辑页面
     * @return bool|\Illuminate\Auth\Access\Response|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-09-15 17:30
     */
    public function edit()
    {
        $info = $this->couponServices->getCouponDetail();
        return view('coupon::admin.coupon.edit', compact('info'));
    }

    /**
     * 优惠券领取记录页面
     * @return bool|\Illuminate\Auth\Access\Response|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     * @author tan bing
     * @date 2021-09-16 14:48
     */
    public function userCouponList()
    {
        $param = $this->couponServices->getRequestParam();
        return view('coupon::admin.coupon.user_coupon_list', compact('param'));
    }

    /**
     * 获取优惠券列表  --分页
     * @return mixed
     * @author tan bing
     * @date 2021-09-15 17:30
     */
    public function getPageData()
    {
        $result = $this->couponServices->getCouponPageData();
        return $this->success($result);
    }

    /**
     * 获取优惠券列表
     * @return mixed
     * @author tan bing
     * @date 2021-09-17 9:56
     */
    public function getCouponList()
    {
        $result = $this->couponServices->getCouponList();
        return $this->success($result);
    }

    /**
     * 添加/编辑优惠券
     * @return mixed
     * @author tan bing
     * @date 2021-09-15 17:31
     */
    public function addAndEditDetail()
    {
        try {
            $result = $this->couponServices->addAndEditDetail();
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success($result);
    }

    /**
     * 删除
     * @return mixed
     * @author tan bing
     * @date 2021-09-15 17:53
     */
    public function delete()
    {
        try {
            $result = $this->couponServices->delete();
            if(!$result)
                return $this->failed('删除失败');
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success();
    }

    /**
     * 批量删除.
     * @return mixed
     * @author tan bing
     * @date 2021-07-19 13:46
     */
    public function batchDelete()
    {
        try {
            $result = $this->couponServices->batchDelete();
            if(!$result)
                return $this->failed('删除失败');
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success();
    }

    /**
     * 编辑状态.
     * @return mixed
     * @author tan bing
     * @date 2021-07-19 13:46
     */
    public function editStatus()
    {
        try {
            $result = $this->couponServices->editStatus();
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }

        return $this->success($result);
    }

    /**
     * 用户优惠券领取记录
     * @return mixed
     * @author tan bing
     * @date 2021-09-16 11:25
     */
    public function getUserCouponList()
    {
        $result = $this->couponServices->getUserCouponList();
        return $this->success($result);
    }

}